<template>
  <div class='container'>
    <el-row>
      <el-col :span='24'>
        <el-card>
          <div class="search">
            <el-row>
              <el-form class="form" label-width="100px" :model="orderParams">
                <el-col :span="9">
                  <el-form-item label="时间">
                    <div class="block">
                      <el-date-picker
                        v-model="value1"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        format="yyyy-MM-dd"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        @change="chooseTimeRange">
                      </el-date-picker>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="所属区域">
                    <el-cascader
                      ref="address"
                      size="large"
                      :options="optionProps"
                      v-model="selectedOptions"
                      @change="handleChange">
                    </el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item>
                    <el-button @click="submitSearch()">搜索</el-button>
                    <!--                    <el-button @click="clearListSearch">重置</el-button>-->
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>
          </div>

          <div slot="header">
            <bread></bread>
          </div>

          <div class="business-table">

            <div class="table-wrapper">
              <el-table
                :data="userList"
                style="width: 100%"
                align='center'
                :header-cell-style="{background:'#eef1f6'}"
              >
                <el-table-column
                  label="日期"
                  prop="day"
                  align='center'>
                </el-table-column>
                <el-table-column
                  prop="sumOrder"
                  label="订单笔数"
                  align='center'
                >
                </el-table-column>
                <el-table-column
                  prop="sumUser"
                  label="下单人数"
                  align='center'
                  :show-overflow-tooltip="true"
                >
                </el-table-column>
                <el-table-column
                  prop="sumMoney"
                  label="订单总金额"
                  align='center'>
                </el-table-column>
                <el-table-column
                  prop="sumPension"
                  label="养老金金额"
                  align='center'>
                </el-table-column>
                <el-table-column
                  prop="platformEarnings"
                  label="平台总收益"
                  align='center'>
                </el-table-column>
                <el-table-column
                  prop="platformNetEarnings"
                  label="平台净收益"
                  align='center'>
                </el-table-column>
<!--                <el-table-column-->
<!--                  prop="productSum"-->
<!--                  label="手续费"-->
<!--                  align='center'>-->
<!--                </el-table-column>-->
              </el-table>
            </div>
          </div>
          <div class="pagination">
            <pagination :pageTotal="pageTotal" @handleCurrentChange="handleCurrentChange"
                        @handleSizeChange="handleSizeChange"></pagination>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import pagination from '../../common/pagination'
import bread from '../../common/bread'
import { formatDate } from 'src/utils/utils'
import {orderDataList, queryAddress, userFunction} from '../../api/api'

export default {
  data () {
    return {
      optionProps: {
        value: 'id',
        label: 'name',
        children: 'child'
      },
      userList: [],
      orderParams: {
        pageNum: 1,
        pageSize: 10,
        startTime: '',
        endTime: '',
        province: '',
        city: '',
        county: ''
      },
      pageTotal: 0,
      value1: '',
      dialogVisible: false,
      userFucParams: {
        editId: '',
        userId: sessionStorage.getItem('userId'),
        type: 0
      },
      selectedOptions: []
    }
  },
  mounted () {
    this.getGoodsList()
    this.queryAddress();
  },
  methods: {
    // 格式化表单数据
    clearForm () {
      this.orderParams = {
        pageNum: 1,
        pageSize: 10,
        startTime: '',
        endTime: '',
        province: '',
        city: '',
        county: ''
      }
    },
    // 清除列表的搜索表单
    clearListSearch () {
      this.clearForm()
    },
    show (scope) {
      console.log(scope)
    },

    handleClick () {
      this.clearForm()
      this.queryAddress()
    },

    // 表格数据
    getGoodsList (type) {
      this.userList = []
      const para = Object.assign({}, this.orderParams)
      orderDataList(para).then(res => {
        console.log(res)
        this.userList = res.data.list
        this.pageTotal = res.data.total
      })
    },
    // 上下分页
    handleCurrentChange (val) {
      this.orderParams.pageNum = val
      this.getGoodsList()
    },
    // 每页显示多少条
    handleSizeChange (val) {
      this.orderParams.pageSize = val
      this.getGoodsList()
    },
    submitSearch () {
      this.getGoodsList()
    },
    showDialog (type, row) {
      this.userFucParams.type = type
      this.userFucParams.editId = row.userId
      this.dialogVisible = true
    },
    getUserFunc () {
      const para = Object.assign({}, this.userFucParams)
      userFunction(para).then(res => {
        console.log(res)
        this.dialogVisible = false
      })
    },
    getDate (date) {
      console.log(date)
    },
    queryAddress() {
      queryAddress().then(res => {
        this.optionProps = res.data;
      })
    },
    handleChange (value) {
      let labels = this.$refs['address'].getCheckedNodes()[0].pathLabels;
      this.orderParams.province = labels[0];
      this.orderParams.city = labels[1] === '全部' ? '' : labels[1];
      this.orderParams.county = labels[2] === '全部' ? '' : labels[2];
    },
    chooseTimeRange (value) {
      console.log(value) // 结果为一个数组，如：["2018-08-04", "2018-08-06"]
      for (var x in value) {
        this.orderParams.startTime = value[0]
        this.orderParams.endTime = value[1]
      }
    }

  },
  components: {
    pagination,
    bread
  }
}
</script>
<style lang='scss'>
  .business-tabs {
    margin: 0 0 10px 0;
  }

  .el-dialog--small {
    width: 600px !important;
  }

  .container {
    .search {
      margin: 0 0 20px 0;
    }

    .el-table {
      .warning-row {
        background-color: oldlace;
      }
    }

    .recommend-tag {
      display: inline-block;
      margin: 4px 0;
      margin-right: 4px;

      &:last-child {
        margin-right: 0;
      }
    }

    .table-footer {
      padding: 10px;
      background: #eef1f6;
    }
  }
</style>
